<template>
  <div class="tab">
    <ul class="tab-header">
      <li class="tab-header-item" :style="{
        width: 100 / list.length + '%',
        color: currentIndex == index ? '#fff' : '#101535',
        backgroundColor: currentIndex == index ? '#101535' : '#fff',
      }" v-for="(item, index) in list" :key="index" @click="tabClick(index)">
        {{ item }}
      </li>
    </ul>
    <div class="tab-content">
      <slot name="content" />
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue";

const { list, current } = defineProps({
  list: {
    type: Array,
    required: true,
    default: [],
  },
  current: {
    type: Number,
    default: 0,
  },
});
const emits = defineEmits(["click", "change"]);
const currentIndex = ref(current);
const tabClick = (index: number) => {
  currentIndex.value = index;
  emits("click", index);
  emits("change", index);
};
</script>
<style lang="scss" scoped>
.tab {
  display: flex;
  flex-direction: column;
  width: 100%;
  font-size: 12px;
}

.tab-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px;
  background-color: #fff;
  border-radius: 80px;
  color: #101535;
}

.tab-header-item {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 6px 16px;
  border-radius: 80px;
  font-size: 12px;
  color: #101535;
}
</style>
